package com

import com.decoder.AES
import com.entity.Input
import com.entity.Output
import com.util.ZlibUtil
import io.netty.buffer.PooledByteBufAllocator
import io.netty.handler.codec.compression.Bzip2Encoder
import io.netty.handler.codec.compression.SnappyFrameEncoder
import kotlin.test.BeforeTest
import kotlin.test.Test

class CompressionTest {


    @BeforeTest
    fun before() {
        System.setProperty("rootDir", "E:\\WorkSpace\\Idea\\Java\\NettySocket/log")
    }

    @Test
    fun test() {


        Bzip2Encoder()
        SnappyFrameEncoder()

        PooledByteBufAllocator.DEFAULT.buffer()

    }


    @Test
    fun test2() {
        val aes = AES()
        var byte = "我是个英雄".toByteArray()
        println("加密前：" + byte.joinToString())
        var str = aes.encrypt(byte)
        println("加密后：$str")
        byte = str.encodeToByteArray()
        println("加密后：" + byte.joinToString())

//        byte = ZlibUtil.compress(byte)
//        println(byte.size)
//        println(byte.joinToString())
//        println(byte.decodeToString())

        println(" ---    解析 ")
//
//        byte = ZlibUtil.decompress(byte)
        byte = aes.decrypt(byte)
        println("解压：" + byte.size)
        println(byte.joinToString())
        println(byte.decodeToString())


        println("--- 二进制数据测试 ---")

        byte = Output()
            .writeLong(100)
            .writeUTF("我是个英雄")
            .toByteArray()

        println(byte.size)
        println(byte.joinToString())


        str = aes.encrypt(byte)
        println("加密后：$str")
        byte = str.encodeToByteArray()
        println("加密后：" + byte.joinToString())

        byte = ZlibUtil.compress(byte)
        println(byte.size)
        println(byte.joinToString())

        println(" ---    解析 ")

        byte = ZlibUtil.decompress(byte)
        byte = aes.decrypt(byte)
        println("解压：" + byte.size)
        println(byte.joinToString())
        val input = Input(byte)
        println(input.readLong())
        println(input.readUTF())
    }


}